#include "EWAUIGraphRect.hpp"

namespace Eyer
{
    EWAUIGraphType EWAUIGraphRect::GetType()
    {
        return EWAUIGraphType::RECT;
    }

    int EWAUIGraphRect::Transform(const Vec2I & _xy, const Vec2I & _parentWH)
    {
        // EyerLog("xy: %d, %d\n", _xy.x(), _xy.y());
        // EyerLog("wh: %d, %d\n", wh.x(), wh.y());
        // EyerLog("pwh: %d, %d\n", _parentWH.x(), _parentWH.y());

        int startX = xy.x() + _xy.x();
        int startY = xy.y() + _xy.y();

        int endX = startX + std::abs(wh.x());
        int endY = startY + std::abs(wh.y());

        if(startX <= 0){
            startX = 0;
        }
        if(startY <= 0){
            startY = 0;
        }

        if(endX >= 0 + std::abs(_parentWH.x())){
            endX = 0 + std::abs(_parentWH.x());
        }
        if(endY >= 0 + std::abs(_parentWH.y())){
            endY = 0 + std::abs(_parentWH.y());
        }

        if(endY <= startY){
            endY = startY;
        }
        if(endX <= startX){
            endX = startX;
        }

        Vec2I startXY(startX, startY);
        Vec2I endXY(endX, endY);

        xy = startXY;
        wh = endXY - startXY;


        /*
        int startX = xy.x() + _xy.x();
        int startY = xy.y() + _xy.y();

        Vec2I startXY(startX, startY);

        xy = startXY;
        */
        return 0;
    }

    bool EWAUIGraphRect::IsValid()
    {
        if(wh.x() <= 0){
            return false;
        }
        if(wh.y() <= 0){
            return false;
        }
        return true;
    }
}